/* jshint esversion: 6 */
import React, {Component} from "react";

import { Image, List } from 'antd-mobile'


import axios from "../../../../http";
import {HashRouter, Link, MemoryRouter, Route} from "react-router-dom";
import {Block} from "../../../../components/block/Block";
import {PRIVATE_ROUTE} from "../../../../route.constants";
import MySchedule from "./MySchedule";
import ScheduleAdd from "./ScheduleAdd";
import { createMemoryHistory} from "history";
import {withRouter} from "react-router";
class Work extends Component {

    constructor(props) {

        super(props);

        this.state={};

    }


    componentDidMount() {
        this.loadData();
    }

    getUserMenu=(menuList:any,code)=>{
        for(let i=0;i<menuList.length;i++){
            if(menuList[i].nameEn===code){
                return menuList[i];
            }
        }
        return null;
    }

    getChildrenByParentId=(menuList:any,parentId)=>{
        let retVal=new Array();
        for(let i=0;i<menuList.length;i++){
            if(menuList[i].pId===parentId){
                retVal.push(menuList[i]);
            }
        }
        return retVal;
    }
    loadData=()=>{

        axios.post('api/core/access/resources/getUserMenuZtreeJson',{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{

                let  data:any=response.data.data;

                let menuOaWork=this.getUserMenu(data,'OA_WORK');

                let menuWorkSchedules=this.getChildrenByParentId(data,menuOaWork.id);

                this.setState({menuWorkSchedules:menuWorkSchedules});

            }).catch(function (error) {
                console.log(error);
            });

    }

    createSubMenu=()=>{
        return (this.state.menuWorkSchedules || []).map(item=>{
            return [<List.Item onClick={()=>{this.props.history.push('/main/'+PRIVATE_ROUTE[item.nameEn])}}>
                {item.nameZh}

            </List.Item>]
        })

    }



    render() {
        return (
            <>

                <Block title={'工作日程'}>
                    <List>
                        {this.createSubMenu()}
                    </List>
                </Block>
            </>
        );
    }
}
export default withRouter(Work)